package com.csair.seam.infrastructure.sso;

import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.boot.web.servlet.ServletListenerRegistrationBean;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.trs.idm.client.filter.GeneralSSOFilter;
import com.trs.idm.client.listener.CoSessionListener;
import com.trs.idm.client.servlet.GetLongUrlServlet;
import com.trs.idm.client.servlet.LoginProxyServlet;

@Configuration
public class SsoConfiguration {
	
	@Bean
	 public ServletRegistrationBean<LoginProxyServlet> registerSsoLogin() {
		ServletRegistrationBean<LoginProxyServlet> registration = new ServletRegistrationBean<>(new LoginProxyServlet(), "/TRSIdSSSOProxyServlet");
		registration.setLoadOnStartup(100);
	    return registration;
	}
	
	@Bean
	public ServletRegistrationBean<GetLongUrlServlet> registerSsoUrl() {
		return new ServletRegistrationBean<>(new GetLongUrlServlet(), "/idsAgents/GetLongUrlServlet");
	}
	
	@Bean
	public FilterRegistrationBean<GeneralSSOFilter> registerSsoFilter() {
		FilterRegistrationBean<GeneralSSOFilter> filterRegistrationBean = new FilterRegistrationBean<>();
		filterRegistrationBean.setFilter(new GeneralSSOFilter());
		filterRegistrationBean.addUrlPatterns("/*");
		return filterRegistrationBean;
	}
	
	@Bean
	public ServletListenerRegistrationBean<CoSessionListener> registerSsoSession() {
		return new ServletListenerRegistrationBean<>(new CoSessionListener());
	}
}
